import React, { Component, createContext } from "react";
import Child1 from "./Child1";

// const context = createContext();
// const { Provider } = context;

// 在进行context传递的时候，传递的Provider和接受的Consumer必须来自于同一个context对象
export const appContext = createContext();
// export const { Provider, Consumer } = context;

class App extends Component {
  state = {
    count: 5,
    name: "tom",
  };

  render() {
    return (
      // Provider组件要套在需要传递数据的那个父元素的外面
      // 还需要一个value属性
      <appContext.Provider
        value={{
          count: this.state.count,
          name: this.state.name,
        }}
      >
        <h2>context上下文</h2>
        <Child1 />
      </appContext.Provider>
    );
  }
}

export default App;
